package com.designmodel.chainmodel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by
 * 过滤链对象
 * @author touni
 * @date 2019/4/2
 * @time 10:20
 */
public class FilterChain {
    //链条上责任处理过滤操作之后需要执行的servlet对象
    private Servlet servlet;

    //定义链条上面的责任人
    List<Filter> filterList = new ArrayList<Filter>(16);
    //定义存储当前责任人的坐标

    int index = 0;

    public void setServlet(Servlet servlet){
        this.servlet = servlet;

    }


    public void doFilter(String request,String response){

        if (index <filterList.size()){
            filterList.get(index++).doFilter(request,response,this);
        }else {
            servlet.service(request,response);
        }


    }















}
